package com.bill.security.token;

import java.io.Serializable;
import java.util.Date;

public class UsernamePasswordToken implements Serializable {
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
private  String algorithm;
private Date  lastaccess;
private String login;
private String password;
private long tokenttl;
public String getAlgorithm() {
	return algorithm;
}
public void setAlgorithm(String algorithm) {
	this.algorithm = algorithm;
}
public Date getLastaccess() {
	return lastaccess;
}
public void setLastaccess(Date lastaccess) {
	this.lastaccess = lastaccess;
}
public String getLogin() {
	return login;
}
public void setLogin(String login) {
	this.login = login;
}
public String getPassword() {
	return password;
}
public void setPassword(String password) {
	this.password = password;
}
public long getTokenttl() {
	return tokenttl;
}
public void setTokenttl(long tokenttl) {
	this.tokenttl = tokenttl+new Date().getTime();
}
public boolean isTokenExpired(){
	return this.getTokenttl()<(new Date().getTime());
}
@Override
public String toString() {
	if(lastaccess==null)lastaccess=new Date();
	return "UsernamePasswordToken [algorithm=" + algorithm + ", lastaccess="
			+ lastaccess.toGMTString() + ", login=" + login + ", password=" + password
			+ ", tokenttl=" + tokenttl + "]";
}
@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((algorithm == null) ? 0 : algorithm.hashCode());
	result = prime * result + ((login == null) ? 0 : login.hashCode());
	result = prime * result + ((password == null) ? 0 : password.hashCode());
	return result;
}
@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	UsernamePasswordToken other = (UsernamePasswordToken) obj;
	if (algorithm == null) {
		if (other.algorithm != null)
			return false;
	} else if (!algorithm.equals(other.algorithm))
		return false;
	if (login == null) {
		if (other.login != null)
			return false;
	} else if (!login.equals(other.login))
		return false;
	if (password == null) {
		if (other.password != null)
			return false;
	} else if (!password.equals(other.password))
		return false;
	return true;
}
public UsernamePasswordToken(String algorithm, String login, String password) {
	super();
	this.algorithm = algorithm;
	this.login = login;
	this.password = password;
}
public UsernamePasswordToken(  String login, String password) {
	super();
	 
	this.login = login;
	this.password = password;
}

public UsernamePasswordToken() {
	super();
	this.tokenttl=new Date().getTime()+3600000;
	this.lastaccess=new Date();
}
public UsernamePasswordToken(String algorithm, Date lastaccess, String login,
		String password, long tokenttl) {
	super();
	this.algorithm = algorithm;
	this.lastaccess = lastaccess;
	this.login = login;
	this.password = password;
	this.tokenttl = tokenttl;
}

}
